@extends('Layouts.iframe')
@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span  class="c-gray en">&gt;</span> 权限管理
        <a class="btn btn-success radius r"  style="line-height:1.6em;margin-top:3px"   href="javascript:location.replace(location.href);" title="刷新"><i  class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
       {{-- <div class="text-c">
            <form class="Huiform" method="post" action="" target="_self">
                <input type="text" class="input-text" style="width:250px" placeholder="权限名称" id="" name="">
                <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜权限节点
                </button>
            </form>
        </div>--}}
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                {{--<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i  class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> --}}
                <a href="javascript:;" onclick="admin_permission_add('添加权限节点','{{ url('admin/permission/create')  }}','','500')"   class="btn btn-primary radius">
                    <i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a></span>
            <span class="r">共有数据：<strong>54</strong> 条</span>
        </div>
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th scope="col" colspan="7">权限节点</th>
            </tr>
        </table>
        @if($page)
            <ul class="msg_list">
                @foreach($page as $k => $item)
                    <li>
                        <div onclick="childrenHIde(this)">
                            <span class="btn_">＋</span>
                            <span>{{ $k+1 }}</span>
                            <span>{{ $item->describe }}</span>
                            <p><a title="编辑" href="javascript:;" style="text-decoration:none" onclick="admin_permission_edit('角色编辑','/admin/permission/{{$item->id}}/edit','{{$item->id}}','','500')" class="label label-primary  radius">
                                        编辑</a> <a title="删除" href="javascript:;" style="text-decoration:none" onclick="admin_permission_del(this,'{{$item->id}}')" class="label label-danger radius">删除</a></p>
                        </div>
                        @if($item->subPermissions)
                            <ul>
                                @foreach($item->subPermissions as $k => $value)
                                    <li>
                                        <div onclick="childrenHIde(this)">
                                            <span class="btn_">＋</span>
                                            <span>{{ $k+1 }}</span>
                                            <span>{{ $value->describe }}</span>
                                            <p><a title="编辑" style="text-decoration:none" href="javascript:;"  onclick="admin_permission_edit('角色编辑','/admin/permission/{{$value->id}}/edit','{{$value->id}}','','500')" class="label label-primary  radius">编辑</a>
                                                <a title="删除" href="javascript:;"  style="text-decoration:none"    onclick="admin_permission_del(this,'{{$value->id}}')" class="label label-danger radius">删除</a></p>
                                        </div>
                                        @if($value->subPermissions)
                                            <ul>
                                                @foreach($value->subPermissions   as $k => $val)
                                                    <li>
                                                        <div>
                                                            <span>{{ $k+1 }}</span>
                                                            <span>{{ $val->describe }}</span>
                                                            <p><a title="编辑" href="javascript:;"  style="text-decoration:none"   onclick="admin_permission_edit('角色编辑','/admin/permission/{{$val->id}}/edit','{{$val->id}}','','500')" class="label label-primary  radius">编辑</a> <a   title="删除" href="javascript:;"  style="text-decoration:none"  onclick="admin_permission_del(this,'{{$val->id}}')" class="label label-danger radius">删除</a></p>
                                                        </div>
                                                    </li>
                                                @endforeach
                                            </ul>
                                        @endif
                                    </li>
                                @endforeach
                            </ul>
                        @endif
                    </li>
                @endforeach
            </ul>
        @endif
    </div>
@endsection
@section('js')
    <style>
        .msg_list li div {
            position: relative;
            padding: 8px 10px;
            margin: 1px 0;
            color: #333;
            border: 1px solid #ddd;
            cursor: pointer;
        }

        .msg_list li div:hover {
            color: #2ea8e5;
            background: #fff;
        }

        .msg_list li div P {
            position: absolute;
            top: 10px;
            right: 10px;
        }

        .msg_list ul {
            display: none;
        }

        .msg_list li li {
            padding-left: 30px;
        }

        .btn_ {
            font-size: 16px;
            margin-right: 10px;
        }
    </style>
    <script type="text/javascript">
        /*
         参数解释：
         title	标题
         url		请求的url
         id		需要操作的数据id
         w		弹出层宽度（缺省调默认值）
         h		弹出层高度（缺省调默认值）
         */
        /*管理员-权限-添加*/
        function admin_permission_add(title, url, w, h) {
            layer_show(title, url, w, h);
        }
        /*管理员-权限-编辑*/
        function admin_permission_edit(title, url, id, w, h) {
            layer_show(title, url, w, h);
        }

        /*管理员-权限-删除*/
        function admin_permission_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    type: 'post',
                    url: '/admin/permission/'+id,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    data:{'_method':'DELETE'},
                    success: function (data) {
                        if(data.code == 0) {
                            $(obj).parents("tr").remove();
                            layer.msg(data.message, {icon: 1, time: 1000});
                        }else{
                            $(obj).parents("tr").remove();
                            layer.msg(data.message, {icon: 2, time: 1000});
                        }
                    },
                    error: function (data) {
                        $(obj).parents("tr").remove();
                        layer.msg('出错啦', {icon: 2, time: 1000});
                    },
                });
            });
        }
        // 权限列表项展开-收起
        function childrenHIde(type) {
            $(type).find('.btn_').text($(type).find('.btn_').text() == '－' ? '＋' : '－')
            $(type).next().slideToggle(100)
        }
    </script>
@endsection